package io;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author by 何坤
 * @Classname TestIO01
 * @Description TODO
 * @Date 2019/10/17 13:14
 */
public class TestIO01 {
    public static void main(String[] args) throws IOException {
        /*File file = new File("D:\\io\\a.txt");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(file.exists());*/


        /*File file = new File("D:" + File.separator + "io" + File.separator+"a.txt");
        System.out.println(file.getParent());
        File parentFile = file.getParentFile();
        parentFile.mkdirs();
        file.createNewFile();*/


        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        File file = new File("D:" + File.separator + "io" + File.separator+"a.txt");
        System.out.println("是否为目录：" + file.isDirectory());
        System.out.println("是否为文件：" + file.isFile());
        if (file.exists() && file.isFile()){
            System.out.println("文件的大小为：" + file.length());
            System.out.println("未格式化的最后的修改时间为：" + file.lastModified());
            System.out.println("格式化后的最后的修改时间为：" + sdf.format(new Date(file.lastModified())));
        }*/


        /*File file = new File("C:" + File.separator + "Users" + File.separator
                + "13055" + File.separator + "Desktop" + File.separator + "学习笔记");
        if (file.exists() && file.isDirectory()){
            File[] result = file.listFiles();
            for (File f : result){
                System.out.println(f);
            }
        }*/

        File file = new File("C:" + File.separator + "Users" + File.separator
                + "13055" + File.separator + "Desktop" + File.separator + "学习笔记");
        listFile(file);
    }

    private static void listFile(File file){
        File[] files = file.listFiles();
        if (files == null && files.length == 0){
            return;
        }
        for (File file1 : files){
            if (file1.isDirectory()){
                listFile(file1);
            }
            if (file1.isFile()){
                System.out.println(file1);
            }
        }
    }
}
